package me.magicall.db.springjdbc;

import me.magicall.db.dao.MapModelDao;
import me.magicall.db.meta.TableMeta;
import me.magicall.db.meta.TableMetaAccessor;
import me.magicall.db.model.BaseModel.MapModel;
import me.magicall.db.model.BaseModel.MapModel.IntIdMapModel;
import me.magicall.db.model.BaseModel.MapModel.LongIdMapModel;
import me.magicall.db.util.DbUtil;

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;

public class MapModelDaoImpl extends UsingTableMetaDao<MapModel<?>> implements MapModelDao {

	public MapModelDaoImpl(final TableMeta tableMeta, final NamedParameterJdbcOperations jdbc, final TableMetaAccessor tableMetaAccessor) {
		super(tableMeta, jdbc, tableMetaAccessor);
	}

	@Override
	protected Object getProperty(final MapModel<?> model, final String fieldName) {
		return model.get(fieldName);
	}

	@Override
	protected void setProperty(final MapModel<?> model, final String fieldName, final Object value) {
		model.set(fieldName, value);
	}

	@Override
	protected MapModel<?> newT() {
		if (DbUtil.idIsInt(getTableMeta())) {
			return new IntIdMapModel();
		} else {
			return new LongIdMapModel();
		}
	}
}
